<?php

namespace app\api\controller;

use think\Controller;
use think\Db;

class Bases extends Father
{
    //基地地图
    public function basesMap(){

        $result = Db::table('baseMap')->where('id',1)->find();
        return json($result);
    }
    //基地列表
    public function selectAllBases(){
        $size = input('get.size');
        $page = input('get.page');
        $data = model('Bases')->order('weight asc,update_time desc')->paginate($size,false,[

            'var_page'=>'page'
        ]);
        $data = $data->toArray();
        if ($page>$data['last_page']) {
            $data = model('Bases')->order('weight asc,update_time desc')->paginate($size, false, [
                'page' => $data['last_page'],
                'var_page' => 'page'
            ]);
            $data = $data->toArray();
        }
        $bases = $data['data'];

        foreach ($bases as $k=>$v){
            $bases[$k]['file'] =json_decode($v['file']);
            $bases[$k]['tag']= explode(",",$bases[$k]['tag']);

        }
        $return['data'] = $bases;

        if ($data){
            $result =[
                'data' => $bases,
                'total' => $data['last_page'],
                'page' => $data['current_page'],
                'size' => '',
                'success' => true,
                'messages' => '查询成功'

            ];

        }else{
            $result =[
                'data' => '',
                'total' => '',
                'page' => '',
                'size' => '',
                'success' => false,
                'messages' => '查询失败'

            ];

        }

        return json($result);
    }

}
